package com.hao.crud.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hao   email：huanghao.0508@qq.com
 * @ClassName：Msg
 * @description ：TODO 用于服务器传递信息给客户端的信息对象封装
 * @create 2020-10-29-15:01
 */
public class Msg {
//    操作成功的代码
    public static final String SUCCESS_CODE ="100";
//    操作失败的代码
    public static final String FAIL_CODE ="200";
//    操作成功的信息
    public static final String SUCCESS_MSG="恭喜你操作成功";
//    操作成功的代码
    public static final String FAIL_MSG="很遗憾!操作失败";

    //服务器操作的状态
    private String code;
//    服务器返回给客户端的信息
    private String msg;
    //用于储存服务给客户端的数据
    private Map<String,Object> extend;
    //获取操作成功从Msg对象
    public static Msg success(){
        return new Msg(SUCCESS_CODE,SUCCESS_MSG);
    }
    //获取操作成功从Msg对象
    public static Msg fail(){
        return new Msg(FAIL_CODE,FAIL_MSG);
    }

    public Msg add(String name,Object data){
        this.getExtend().put(name,data);
        return this;
    }

    public Msg() {
    }

    public Msg(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.extend = new HashMap<>();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

    @Override
    public String toString() {
        return "Msg{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", extend=" + extend +
                '}';
    }
}
